<?php
/**
 * 合作商户控制器
 */
class Merchant extends Weixin_Controller{
	function __construct()
	{
		parent::__construct();

		$this->load->model('MerchantStore_model','store');
	}

	/**
	 * 合作商户首页
	 * @DateTime 2017-07-07
	 * @author zyl
	 * @return   [type]     [description]
	 */
	function index(){
		//获取活动列表
		$this->load->model('Activity_model','activity');
		$data['activity'] = $this->activity->getActivityList();

		//获取首页门店列表
		$data['type'] = $this->store->getAppIndex();
		// print_r($data['stores']);die();
		$this->load->view('weixin/index',$data);
	}
	
	/**
	 * 商户(门店)列表
	 * @DateTime 2017-07-31
	 * @author zyl
	 * @param    integer    $type [description]
	 * @return   [type]           [description]
	 */
	function merchantList($type=0){
		$where = array(
				'status'  => 1,
				'type'    => $type,
			);
		$list = $this->store->getStoreList($where);
		foreach($list as &$v){
			$v['imgs'] = json_decode($v['imgs'],true);
		}
		$this->load->model('MerchantType_model','type');
		$data['type_id'] = $type;
		$type = $this->type->getTypeById($type);
		$data['type'] = $type['name'];
		// print_r($list);die();
		$data['list'] = $list;

		$this->load->view('weixin/merchant/coMerchant',$data);
		// $this->load->view('APP/merchant/merchantList');
	}

	/**
	 * 微信ajax动态加载门店列表
	 * @DateTime 2017-08-25
	 * @author xyl
	 */
	function WeixinajaxgetStoreList()
	{
		$post = $this->input->post();
		$where = array(
				'status'  => 1,
				'type'    => $post['type'],
			);
		$list = $this->store->getStoreList($where,'create_time desc',$post['page']);
		foreach($list as &$v){
			$v['imgs'] = json_decode($v['imgs'],true);
		}
		echo json_encode($list);return;
	}

	/**
	 * 门店详情
	 * @DateTime 2017-08-22
	 * @author zyl
	 * @param    [type]     $id [description]
	 * @return   [type]         [description]
	 */
	function merchantDetail($id)
	{
		$store = $this->store->getStoreById($id);
		if ($store) {
			$store['imgs'] = json_decode($store['imgs'],true);
		}
		//获取相似商家
		$like_store = $this->store->getLikeStore($store['type'],$id);
		if ($like_store) {
			foreach ($like_store as &$v) {
				$v['imgs'] = json_decode($v['imgs'],true);
			}
		}
		
		$data['like_store'] = $like_store;
		$this->load->model('GoodsAlbum_model','album');
		$album = $this->album->getAlbum($id);
		$data['album'] = $album;
		$data['store'] = $store;
		$this->load->view('weixin/merchant/merchantDetail',$data);
	}
	function coMerchant(){
		$this->load->view('weixin/merchant/coMerchant');
	}
}